package com.business.system.controller;

import com.business.system.service.ITbBusinessService;
import com.business.system.vo.*;
import com.common.untils.CommonResult;
import com.common.untils.OSSUntil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author pgx
 * @since 2022-08-31
 */
@RestController
@RequestMapping("/system/tbBusiness")
public class TbBusinessController {
   @Autowired
    private ITbBusinessService iTbBusinessService;
    //页面回显
   @PostMapping("/findAllBusiness")
    public CommonResult findAllBusiness(@RequestBody BusinessVo businessVo){
      return iTbBusinessService.findAllBusiness(businessVo);
   }
   //详细信息
    @PostMapping("detailedMsg/{id}")
    public CommonResult detailedMsg(@PathVariable Integer id){
       return iTbBusinessService.detailedMsg(id);
    }
    //商家注册审核
    @PostMapping("/auditBusiness")
    public CommonResult auditBusiness(@RequestBody AuditBusinessVo auditBusinessVo,HttpServletRequest request){
        String homeToken = request.getHeader("homeToken");
        return iTbBusinessService.auditBusiness(auditBusinessVo,homeToken);
    }
    //审核页面回显
    @PostMapping("findAuditMsg")
    public CommonResult findAuditMsg(@RequestBody AuditMsg auditMsg){
        return  iTbBusinessService.findAuditMsg(auditMsg);
    }
    //审核页面详细信息
    @PostMapping("auditDetailedMsg/{id}")
    public CommonResult auditDetailedMsg(@PathVariable Integer id){
       return iTbBusinessService.auditDetailedMsg(id);
    }
    //审核通过接口
    @PostMapping("passAudit")
    public CommonResult passAudit(@RequestBody PassAuditVo passAuditVo,HttpServletRequest request){
        String token = request.getHeader("token");
        return iTbBusinessService.passAudit(passAuditVo,token);
    }
    //审核驳回接口
    @PostMapping("turnAudit")
    public CommonResult turnAudit(@RequestBody PassAuditVo passAuditVo, HttpServletRequest request){
        String token = request.getHeader("token");
        return iTbBusinessService.turnAudit(passAuditVo,token);
    }
    //文件上传接口
    @PostMapping("/upload")
    public CommonResult upload(MultipartFile file){
        String path = OSSUntil.upload(file);
        return new CommonResult(2000,"上传成功",path);
    }
    //查询部分商家信息
    @GetMapping("/findBusinessMsg")
    public CommonResult findBusinessMsg(HttpServletRequest request){
        String homeToken = request.getHeader("homeToken");
        System.out.println(homeToken);
        return iTbBusinessService.findBusinessMsg(homeToken);
    }
   @PostMapping("editBusinessMsg")
    public CommonResult editBusinessMsg(HttpServletRequest request,@RequestBody AuditBusinessVo auditBusinessVo){
       String homeToken = request.getHeader("homeToken");
       return  iTbBusinessService.editBusinessMsg(homeToken,auditBusinessVo);
   }
   @PostMapping("withdrawamount/{withdrawamount}")
    public CommonResult withdrawamount(@PathVariable double withdrawamount,HttpServletRequest request){
       String homeToken = request.getHeader("homeToken");
       return iTbBusinessService.withdrawamount(withdrawamount,homeToken);
   }
}
